package password

import (
	"fmt"

	"gitee.com/liumou_site/gcs"
)

// ChangeUserPassword 修改Linux用户密码
func ChangeUserPassword(username, newPassword string, sudo *gcs.ApiSudo) error {
	cmd := fmt.Sprintf("echo '%s:%s' | chpasswd", username, newPassword)
	sudo.RunSudo(cmd)
	if sudo.Err != nil {
		return fmt.Errorf("修改用户密码失败: %v, 输出: %s", sudo.Err, sudo.Strings)
	}
	return nil
}
